﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>部门管理</title>
    <!--freemarker引入模板文件 使用相对路径来引入的-->
    <#include "../common/link.ftl" >
    <link rel="stylesheet" type="text/css" href="/js/plugins/bootstrap-select/bootstrap-select.css"/>
    <script src="/js/plugins/bootstrap-select/bootstrap-select.js"></script>
    <script>
        $(function () {
            //新增/编辑按钮点击事件
            $(".btn-input").click(function () {
                //清除模态框的数据
                //数据复原
                $("#editForm").clearForm(true);
                $('#associationId').selectpicker('val', '');
                //$("#editForm")[0].reset(); //不能清除隐藏域
                //获取事件源绑定的数据 使用data方法可以很方便获取data-*开头的属性的数据
                var json = $(this).data("json");
                if(json){ //json有数据代表是编辑
                    $(".modal-title").html("部门编辑");
                    $("#editForm input[name='id']").val(json.id);
                    $("#editForm input[name='name']").val(json.name);
                    $("#editForm input[name='email']").val(json.email);
                    $("#editForm input[name='dutyName']").val(json.dutyName);
                    $("#editForm input[name='dutyMobile']").val(json.dutyMobile);
                    $("#editForm textarea[name='sn']").val(json.sn);

                    var associationId = json.associationId;
                    $('#associationId').selectpicker('val', associationId);  //插件回显有数组
                    $('#associationId').selectpicker('refresh');   //刷新
                }

                //打开模态框
                $("#myModal").modal('show');
            })

            //保存
            $(".btn-submit").click(function () {
                //使用jquery-form插件来提交异步表单(有表单时会使用该插件,写的代码比较少)
                $("#editForm").ajaxSubmit(handlerMessage)
            })

           //删除按钮
           $(".btn-delete").click(function () {
                //获取当前点击的部门id
               var id = $(this).data('id');
               //提示确认框
               $.messager.confirm("警告","是否确认删除?",function () {
                   //发送ajax请求
                   $.get('/department/delete.do',{id:id},handlerMessage)
               })
           })


        })
    </script>
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <!--页面头部-->
    <#include "../common/navbarAsso.ftl" >
    <!--菜单回显 声明变量设置值-->
    <#assign currentMenu="department"/>
    <!--菜单-->
    <#include "../common/menuAsso.ftl" >
    <div class="content-wrapper">
        <section class="content-header">
            <h1>部门管理</h1>
        </section>
        <section class="content">
            <div class="box">
                <!--高级查询--->
                <form class="form-inline" id="searchForm" action="/department/listAsso.do" method="post">
                    <input type="hidden" name="currentPage" id="currentPage" value="1">
                    <div class="form-group">
                        <label for="keyword">关键字：</label>
                        <input type="text" class="form-control" id="keyword" name="keyword" value="${qo.keyword!}" placeholder="请输入部门名称/邮箱">
                    </div>
                    &nbsp;
                    <div class="form-group">
                        <label for="keyword">负责人：</label>
                        <input type="text" class="form-control" id="duty" name="duty" value="${qo.duty!}" placeholder="请输入负责人">
                    </div>
                    &nbsp;
                    <button id="btn_query" class="btn btn-primary"><span class="glyphicon glyphicon-search"></span> 查询</button>
                    <a href="JavaScript:;" class="btn btn-success btn-input" style="margin: 10px">
                        <span class="glyphicon glyphicon-plus"></span> 添加
                    </a>
                </form>
                <!--编写内容-->
                <div class="box-body table-responsive no-padding ">

                    <table class="table table-hover table-bordered">
                        <tr>
                            <th>编号</th>
                            <th>部门名称</th>
                            <th>部门邮箱</th>
                            <th>部门负责人</th>
                            <th>联系方式</th>
                            <th>备注</th>
                            <th>操作</th>
                        </tr>
                            <#list page.list as department>
                                  <tr>
                                      <!--freemarker 如果取值时是空值 会报错-->
                                      <td>${department_index+1}</td>
                                      <td>${department.name!}</td>
                                      <td>${department.email!}</td>
                                      <td>${department.dutyName!}</td>
                                      <td>${department.dutyMobile!}</td>
                                      <td>${department.sn!}</td>
                                      <td>
                                          <!-- 使用data-*绑定自定义数据-->
                                          <a href="JavaScript:;"
                                             class="btn btn-info btn-xs btn-input"
                                             data-json='${department.jsonString}' >
                                              <span class="glyphicon glyphicon-pencil"></span> 编辑
                                          </a>
                                          <a href="JavaScript:;"
                                             class="btn btn-danger btn-xs btn-delete"
                                                data-id='${department.id}'>
                                              <span class="glyphicon glyphicon-trash"></span> 删除
                                          </a>
                                      </td>
                                  </tr>
                            </#list>
                    </table>
                    <!--分页-->
                    <#include "../common/page.ftl">
                </div>
            </div>
        </section>
    </div>
     <#include "../common/footer.ftl">
</div>


<!-- Modal模态框 -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">部门新增</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/department/saveOrUpdate2.do" method="post" id="editForm">
                    <input type="hidden" name="id">
                    <div class="form-group" style="margin-top: 10px;">
                        <label for="name" class="col-sm-3 control-label">部门名称：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="name" name="name"
                                   placeholder="请输入部门名称">
                        </div>
                    </div>

                    <div class="form-group" style="margin-top: 10px;">
                        <label for="email" class="col-sm-3 control-label">部门邮箱：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="email" name="email"
                                   placeholder="请输入部门邮箱">
                        </div>
                    </div>

                    <div class="form-group" style="margin-top: 10px;">
                        <label for="dutyName" class="col-sm-3 control-label">部门负责人：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="dutyName" name="dutyName"
                                   placeholder="请输入部门负责人">
                        </div>
                    </div>

                    <div class="form-group" style="margin-top: 10px;">
                        <label for="dutyName" class="col-sm-3 control-label">联系方式：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="dutyName" name="dutyMobile"
                                   placeholder="请输入联系方式">
                        </div>
                    </div>

                    <div class="form-group" style="margin-top: 10px;">
                        <label for="sn" class="col-sm-3 control-label">备注：</label>
                        <div class="col-sm-6">
                            <textarea class="form-control" name="sn" id="sn"></textarea>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary btn-submit">保存</button>
            </div>
        </div>
    </div>
</div>

</body>
</html>
